package FloodFill;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: ywk
 * @date: 2021-01-02
 */
public class 区间交集 {
    public static void join(int[][] arr1, int[][] arr2) {
        int len1 = arr1.length;
        int len2 = arr2.length;
        List<Interval> result = new ArrayList<>();
        int j = 0;
        int i = 0;
        out:
        while (i < len1 && j < len2) {
            int[] arrE1 = arr1[i];
            int[] arrE2 = arr2[j];
            int left1 = arrE1[0], right1 = arrE1[1];
            int left2 = arrE2[0], right2 = arrE2[1];
            if (!(left2 > right1 || left1 > right2)) {
                Interval interval = new Interval();
                interval.start = Math.max(left1, left2);
                interval.end = Math.min(right1, right2);
                result.add(interval);
            }
            if (right2 >= right1) {
                i++;
            } else {
                j++;
            }
        }
        System.out.println(result);
    }

    public static void main(String[] args) {
        join(new int[][]{{0, 2}, {5, 10}, {13, 23}, {24, 25}},
                new int[][]{{1, 5}, {8, 12}, {15, 24}, {25, 26}});
    }
}
